package com.itheima.domain.db;


import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

//测灵魂报告表类   暂定为每个用户只有一份
@Data
@NoArgsConstructor


public class Result<T> implements Serializable {
    private static final long serialVersionUID = -8713837118340960775L;

    /** 成功*/
    private static final String SUCCESS = "0";
    /** 警告*/
    private static final String WARN = "1";
    /** 异常 失败*/
    private static final String FAIL = "500";

    private String code;

    private String msg;

    private Object data;
    public Result(String code) {
        this.code = code;
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 失败并返回数据
     * @param data
     * @return
     */
    public static Result error(Object data) {
        return new Result(FAIL, data);
    }

    /**
     * 警告并返回数据
     * @param data
     * @return
     */
    public static Result warn(Object data) {
        return new Result(WARN, data);
    }

    /**
     * 成功并返回数据
     * @param msg
     * @param data
     * @return
     */
    public static Result ok(String msg, Object data) {
        return new Result(SUCCESS, msg, data);
    }

    /**
     * 带数据
     * @param data
     * @return
     */
    public static Result ok(Object data) {
        return new Result(SUCCESS,data);
    }

    /**
     * 成功返回通用数据
     * @return
     */
//    public static Result ok() {
//        return new Result(SUCCESS, "微信登录成功");
//    }

    public static Result ok() {
        return  Result.ok( "微信登录成功");
    }

    public static Result error() {
        return Result.error("微信登录失败");
    }

}
